class StoreManagerController < ApplicationController
  def home
  end

  def view_requested_openings
    @positions = Position.all
  end

  def approve
    require 'json'
    require 'net/http'

    @position = Position.find(params[:id])

    if @position.posting_id == nil
      @position.posting_id = params[:id]
    end

    if @position.store_id == nil
      @position.store_id = 1
    end

    if @position.start_date == nil
      start_date = Date.today
      @position.start_date = start_date.to_s
    end

    if @position.end_date == nil
      end_date = start_date + 365
      @position.end_date = end_date.to_s
    end

    uri = URI.parse('http://140.211.68.130/SetOpenPosition')
    response = Net::HTTP.post_form(uri, @position.attributes)

    @position.destroy

    redirect_to store_manager_view_requested_openings_path(store_id: 1)
  end

  def destroy
    @position = Position.find(params[:id])
    @position.destroy

    redirect_to store_manager_view_requested_openings_path(store_id: 1)
  end
end
